<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Search Purchase Orders" >
                        <f:facet name="header" >                            
                            <h:outputLabel value="SEARCH RETURN BILL"/>     

                            <h:panelGrid columns="6" >
                                <h:outputLabel value="From Date"/>
                                <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                </p:calendar>
                                <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createReturnWholeSaleBills}"/>
                               <p:commandButton id="btnSearchAll" ajax="false" value="Search All" action="#{searchController.createReturnWholeSaleAllBills()}"/>
                                <p:spacer height="30"/>
                                </h:panelGrid>
                            <h:panelGrid columns="3" >
                                <h:outputLabel value="Sale Bill No"/>   
                                <h:outputLabel value="Return Bill No"/> 
                                <h:outputLabel value="Net Total"/>
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.refBillNo}" />   
                                <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                <p:inputText autocomplete="off" value="#{searchController.searchKeyword.netTotal}"/>                               
                                <h:outputLabel/><h:outputLabel/>
                            </h:panelGrid>

                        </f:facet>


                        <p:dataTable 
                            id="tblBills" 
                            value="#{searchController.bills}" 
                            var="bill"  
                            paginator="true"
                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="5,10,15"
                            >
                            <p:column headerText="Sale Bill No" >                              
                                <h:outputLabel value="#{bill.billedBill.deptId}" ></h:outputLabel>
                            </p:column>  

                            <p:column headerText="Return Bill No"  >                              
                                <h:outputLabel value="#{bill.deptId}" ></h:outputLabel>
                            </p:column>  
                            <p:column headerText="Item Return at"  >                               
                                <h:outputLabel value="#{bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>                                   
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>                             
                            </p:column>                 
                            <p:column headerText="Item Return by" >                               
                                <h:outputLabel value="#{bill.creater.webUserPerson.name}" >                                      
                                </h:outputLabel>                                
                                <br/>
                                <h:panelGroup rendered="#{bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled By " />
                                    <h:outputLabel style="color: red;" rendered="#{bill.cancelled}" value="#{bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>                             
                            </p:column>        
                            <p:column>
                                <p:commandButton ajax="false" disabled="#{bill.checkActiveReturnCashBill() or bill.cancelled}" 
                                                 value="Cancel Return Item Bill" action="pharmacy_reprint_bill_return_pre">
                                    <f:setPropertyActionListener value="#{bill}" target="#{pharmacyBillSearch.bill}"/>
                                </p:commandButton>                                
                            </p:column>

                            <p:column>
                                <p:dataTable value="#{bill.returnCashBills}" var="rb">
                                    <p:column  >                                                               
                                        <h:outputLabel  value="#{rb.deptId}"/>                                   
                                    </p:column>
                                    <p:column >
                                        <h:outputLabel value="#{rb.createdAt}" >
                                            <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                        </h:outputLabel>
                                        <br/>
                                        <h:panelGroup rendered="#{rb.cancelled}" >
                                            <h:outputLabel style="color: red;" value="Cancelled at " />
                                            <h:outputLabel style="color: red;" rendered="#{rb.cancelled}"
                                                           value="#{rb.cancelledBill.createdAt}" >
                                                <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                            </h:outputLabel>
                                        </h:panelGroup>                               
                                    </p:column> 
                                    <p:column >                               
                                        <h:outputLabel value="#{rb.creater.webUserPerson.name}" >                                      
                                        </h:outputLabel>                                
                                        <br/>
                                        <h:panelGroup rendered="#{rb.cancelled}" >
                                            <h:outputLabel style="color: red;" value="Cancelled by " />
                                            <h:outputLabel style="color: red;" rendered="#{rb.cancelled}"
                                                           value="#{rb.cancelledBill.creater.webUserPerson.name}" >                                       
                                            </h:outputLabel>
                                        </h:panelGroup> 
                                    </p:column>                                                     
                                    <p:column >
                                        <h:outputLabel value="#{rb.netTotal}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>                                  
                                    </p:column>
                                    <p:column>
                                        <p:commandButton ajax="false"  value="Cancel Refund Cash Bill" action="pharmacy_reprint_bill_return_cash" disabled="#{rb.cancelled}">
                                            <f:setPropertyActionListener value="#{rb}" target="#{pharmacyBillSearch.bill}"/>
                                        </p:commandButton>     
                                    </p:column>
                                </p:dataTable>
                            </p:column>


                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
